var planId=getQueryString("ids")
$(function () {
    $("#jqGrid").Grid({
        url: '../devrecordoption/list?planId='+planId,
        colModel: [
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            {label: '维护库选项名称', name: 'mainBaseName', index: 'MAIN_BASE_NAME', width: 80},
     /*       {label: '维护库选项ID', name: 'mainBaseId', index: 'MAIN_BASE_ID', width: 80},*/
            {label: '巡检计划', name: 'patrolPlanName', index: 'PATROL_PLAN', width: 80},
            {label: '计划执行人', name: 'planUserName', index: 'PLAN_USER', width: 80},
            {label: '计划执行时间', name: 'planDate', index: 'PLAN_DATE', width: 80,formatter:function (value) {
                    return transDate(value,'yyyy-MM-dd')
                }},
            {label: '是否正常', name: 'status', index: 'STATUS', width: 80,formatter:function (value) {
                    return sysEnums.IS_NORMAL[value]
                }},

           /*
            {label: '维护规程基础', name: 'mainRulesBase', index: 'MAIN_RULES_BASE', width: 80},
               {label: '规程管理ID', name: 'recordId', index: 'RECORD_ID', width: 80},

            {label: '检查人ID', name: 'checkId', index: 'CHECK_ID', width: 80},
            {label: '检查人', name: 'checkName', index: 'CHECK_NAME', width: 80},
            {label: '确认结果', name: 'sureFlag', index: 'SURE_FLAG', width: 80},
            {label: '删除标识', name: 'delFlag', index: 'DEL_FLAG', width: 80},
            {label: '检查日期', name: 'chekDate', index: 'CHEK_DATE', width: 80},
            {label: '巡检计划', name: 'patrolPlan', index: 'PATROL_PLAN', width: 80},
            {label: '检查结果', name: 'checkFlag', index: 'CHECK_FLAG', width: 80},
            {label: '修改人员', name: 'updateUser', index: 'UPDATE_USER', width: 80},
            {label: '修改时间', name: 'updateDate', index: 'UPDATE_DATE', width: 80},
            {label: '添加人员', name: 'createUser', index: 'CREATE_USER', width: 80},
            {label: '添加时间', name: 'createDate', index: 'CREATE_DATE', width: 80},*/]
    });
  //  vm.getMainBaseId()
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        devRecordOption: {
            mainBaseId: '',
            id: '',
            delFlag: '',
            chekDate: '',
            checkFlag: '',
            recordId: '',
            mainBaseName: '',
            updateUser: '',
            updateDate: '',
            createUser: '',
            createDate: '',
            planUser: '',
            planDate: '',
            status: '',
            patrolPlan: '',
            mainRulesBase: '',
            checkId: '',
            checkName: '',
            sureFlag: '',
        },
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ],
            status: [
                {required: true, message: '检查结果不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        //手动生成巡检记录
        getMainBaseId:function(){
            Ajax.request({
                url: "../devrecordoption/saveMainBaseId/" + planId,
                async: true,
                successCallback: function (r) {
                 //   vm.devRecordOption = r.devRecordOption;
                }
            });
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.devRecordOption = {
                mainBaseId:'',
                id: '',
                delFlag: '',
                chekDate: '',
                checkFlag: '',
                recordId: '',
                mainBaseName: '',
                updateUser: '',
                updateDate: '',
                createUser: '',
                createDate: '',
                planUser: '',
                planDate: '',
                status: 2,
                patrolPlan: '',
                mainRulesBase: '',
                checkId: '',
                checkName: '',
                sureFlag: '',
            };
        },
        update: function (event) {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id);
        },
        saveOrUpdate: function (event) {
            var url = vm.devRecordOption.id == (null || '') ? "../devrecordoption/save" : "../devrecordoption/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.devRecordOption),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../devrecordoption/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../devrecordoption/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.devRecordOption = r.devRecordOption;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },
        saveRecordOption:function(){
            vm.devRecordOption.mainBaseId=ids
        },
        //处理
        deal: function () {
            var rows = getSelectedRowData("#jqGrid");
            var ids=rows.id;

            if (rows.status == "是") {
                alert('检查结果已确认,请勿重复操作!', function (index) {
                    vm.reload();
                });
                return;
            }
            if (ids == null) {
                return;
            }
            vm.getInfo(ids);
            openWindow({
                title: "处理",
                area: ['550px', '300px'],
                content: jQuery("#deal"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    Ajax.request({
                        url: '../devrecordoption/deal',
                        params: JSON.stringify(vm.devRecordOption),
                        type: 'POST',
                        contentType: "application/json",
                        successCallback: function (result) {
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                        }
                    });
                }
            });
        },
    }
});
